using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
using Microsoft.Xna.Framework.Content.Pipeline.Processors;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;

using TWrite = WindowsGame1Content.Tilemap.TilemapContent;

namespace WindowsGame1Content.Tilemap
{
    [ContentTypeWriter]
    public class TilemapWriter : ContentTypeWriter<TWrite>
    {
        protected override void Write(ContentWriter output, TWrite value)
        {
            output.Write(value.mapWidth);
            output.Write(value.mapHeight);
            output.Write(value.layers.Count);
            foreach (MapLayer layer in value.layers)
                WriteLayer(output, layer, value.mapWidth, value.mapHeight);
        }
        private void WriteLayer(ContentWriter output, MapLayer layer, int width, int height)
        {
            for (int y = 0; y < height; y++)
                for (int x = 0; x < width; x++)
                    output.Write(layer.GetTile(x, y));
        }
        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return "WindowsGame1.TilemapReader, WindowsGame1";
        }
    }
}
